<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button {
            padding: 10px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            background-color: #f9f9f9;
            white-space: pre-wrap;
        }
    </style>
</head>
<body>
    <h1>图书推荐系统 - 登录测试</h1>
    
    <div class="form-group">
        <label for="account">账号:</label>
        <input type="text" id="account" value="admin">
    </div>
    
    <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" value="123456">
    </div>
    
    <button onclick="login()">登录</button>
    
    <div id="result"></div>
    
    <script>
        function login() {
            const account = document.getElementById('account').value;
            const password = document.getElementById('password').value;
            const resultDiv = document.getElementById('result');
            
            resultDiv.textContent = '正在登录...';
            
            fetch('http://localhost:8080/api/auth/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    account: account,
                    password: password
                })
            })
            .then(response => {
                if (!response.ok) {
                    return response.text().then(text => {
                        throw new Error(`状态码: ${response.status}, 错误信息: ${text}`);
                    });
                }
                return response.json();
            })
            .then(data => {
                resultDiv.textContent = '登录成功！\n\n' + JSON.stringify(data, null, 2);
            })
            .catch(error => {
                resultDiv.textContent = '登录失败：\n' + error.message;
            });
        }
    </script>
</body>
</html>
